package com.noahplat.person.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.person.pojo.Defecate;
import com.noahplat.person.service.DefecateService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @ClassName: DefecateController
 * @Description: 排便情况controller
 * @Author 李景星
 * @Date 2021/3/8
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/defecate")
@Validated
public class DefecateController {

    @Autowired
    private DefecateService defecateService;

    /**
     * 获取所有的排便情况字典
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DefecateController:getDefecate')")
    @GetMapping("/getDefecate")
    public Result getDefecate(){
        return defecateService.getDefecate();
    }

    /**
     * 添加排便情况
     * @param defecate
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DefecateController:addDefecate')")
    @PostMapping("/addDefecate")
    public Result addDefecate(@RequestBody Defecate defecate){
        return defecateService.addDefecate(defecate);
    }
    /**
     * 修改排便情况
     * @param defecate
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DefecateController:updateDefecate')")
    @PutMapping("/updateDefecate")
    public Result updateDefecate(@RequestBody Defecate defecate){
        return defecateService.updateDefecate(defecate);
    }
    /**
     * 删除排便情况
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DefecateController:delDefecate')")
    @DeleteMapping("/delDefecate")
    public Result delDefecate(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return defecateService.delDefecate(id);
    }
    /**
     * 分页获取排便情况
     * @param page
     * @param limit
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DefecateController:getAdminDefecate')")
    @GetMapping("/getAdminDefecate")
    public Result getAdminDefecate(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer limit){
        return defecateService.getAdminDefecate(page, limit);
    }
    /**
     * 获取排便情况详细信息
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DefecateController:getDefecateById')")
    @GetMapping("/getDefecateById")
    public Result getDefecateById(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return defecateService.getDefecateById(id);
    }
}
